//
//  PhotoEntity.m
//  PhotoGirl
//
//  Created by comic on 4/23/13.
//  Copyright (c) 2013 comic. All rights reserved.
//

#import "PhotoEntity.h"
#import "TileImageView.h"
@implementation PhotoEntity
@synthesize imageId=_imageId;
@synthesize imageName=_imageName;
@synthesize maxWidth,maxHeight,tileX,tileY;

- (int)getMaxResolution {
    int resolution=0;
    //    int tmp_max=MAX([photo.max_height intValue], [photo.max_Width intValue]);
    int tmp_xmax=self.maxWidth;
    int tmp_ymax=self.maxHeight;
    while (tmp_xmax>self.tileX || tmp_ymax>self.tileY ) {
        resolution++;
        tmp_xmax=tmp_xmax/2;
        tmp_ymax=tmp_ymax/2;
    }
    return resolution;
}
- (int)getMaxRowWithResolution:(int)resolution {
    int maxResolution=[self getMaxResolution];
    int height=maxHeight/powf(2,maxResolution-resolution);
    return floorf(height/tileY);
}
- (int) getMaxColWithResolution:(int)resolution {
    int maxResolution=[self getMaxResolution];
    int height=maxWidth/powf(2,maxResolution-resolution);
    return floorf(height/tileX);
}
-(CGSize) getSizeInResolution: (int) resolution {
    CGSize size;
    size.width=maxWidth/powf(2,[self getMaxResolution]-resolution);
    size.height=maxHeight/powf(2,[self getMaxResolution]-resolution);
    return size;
}
-(CGSize) getTileSize:(TileImageView* ) tile {
    CGSize sizeResolution=[self getSizeInResolution:tile.resolution];
    sizeResolution.width=sizeResolution.width-tileX*tile.col;
    if (sizeResolution.width>tileX) sizeResolution.width=tileX;
    sizeResolution.height=sizeResolution.height-tileY*tile.row;
    if (sizeResolution.height>tileY) sizeResolution.height=tileY;
    return sizeResolution;
}

@end
